package scala.begin

object MainOB {
   def main(args: Array[String]): Unit = {

      val list = List(2, 4, 6, 8, 10);
      val x = list.foldLeft(100)((a, b) => a + b);
      println(x);

      val strings = List("Scala", "Language");
      println(joinString(strings));

      println(factorial(30));

      println("\n\n\n\n");
      val cc = list(1)
      println("CCCC: " + cc)
      // list.dropRight(n)
   }

   def findMax(a: Int, b: Int): Int = {
      if (a > b)
         return a;
      else
         return b;
   }

   //default value if parameters
   def joinString(strings: List[String], separator: String = " "): String = {
      strings.mkString(separator);
   }

   //using nested method

   def factorial(i: Int): Int = {
         def fact(i: Int, result: Int = 1): Int = {
            if (i <= 1)
               result;
            else
               fact(i - 1, i * result);
         }

      fact(i);
   }

}